<!--
  项目流程-项目初步评估
  @author YangMiao 1939724848@qq.com
  @date 2022/3/29 14:09
  @version 1.0.0
-->
<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="12">
          <el-form-item :label="$t('项目名称')" prop="dealId">
            <MainBodySelect
              v-model="form.dealId"
              parameters="deal"
              disabled
              @change="dealIdChange"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('网址')" prop="internetSite">
            <el-input v-model="form.internetSite" :placeholder="$t('网址')" show-word-limit maxlength="32" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('成立时间')" prop="established">
            <el-date-picker
              v-model="form.established"
              clearable
              style="width: 200px"
              type="date"
              value-format="yyyy-MM-dd"
              :placeholder="$t('成立时间')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('法人')" prop="legalPerson">
            <el-input v-model="form.legalPerson" :placeholder="$t('法人')" show-word-limit maxlength="32" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('注册资金')" prop="registeredCapital">
            <Money v-model="form.registeredCapital" :placeholder="$t('注册资金')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('注册地')" prop="registration">
            <el-input v-model="form.registration" :placeholder="$t('注册地')" show-word-limit maxlength="50" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('项目来源')" prop="projectSource">
            <el-input v-model="form.projectSource" :placeholder="$t('项目来源')" show-word-limit maxlength="32" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('公司简介')" prop="companyProfile">
            <el-input v-model="form.companyProfile" type="textarea" :placeholder="$t('公司简介')" show-word-limit maxlength="2000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('投资逻辑')" prop="investmentLogic">
            <el-input v-model="form.investmentLogic" type="textarea" :placeholder="$t('投资逻辑')" show-word-limit maxlength="2000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('行业需求')" prop="industryNeeds">
            <el-input v-model="form.industryNeeds" type="textarea" :placeholder="$t('行业需求')" show-word-limit maxlength="2000" />
          </el-form-item>
        </el-col>
        <!--        <el-col :span="24">
          <el-form-item :label="$t('股权结构')" prop="industryNeeds">
            <el-input v-model="form.remark" type="textarea" :placeholder="$t('股权结构')" show-word-limit maxlength="2000" />
          </el-form-item>
        </el-col>-->

        <!--    核心产品或服务    -->
        <formInnerTable
          title="核心产品或服务"
          :data-list="form.coreProductsList"
          :init-data="initData.coreProducts"
        >
          <el-table-column :label="$t('产品/服务')">
            <template slot="header" slot-scope="{}">
              <i v-if="validate" style="color: #ff4949; margin-right: 4px">*</i>
              <span>{{ $t("产品/服务") }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'coreProductsList.' + scope.$index + '.productService'"
                :rules="rules.productService"
              >
                <el-input v-model="scope.row.productService" type="textarea" show-word-limit :maxlength="2000" />
              </el-form-item>
            </template>
          </el-table-column>
        </formInnerTable>
        <!--    未来关键里程碑    -->
        <formInnerTable
          title="未来关键里程碑"
          :data-list="form.futureMilestonesList"
          :init-data="initData.coreProducts"
        >
          <el-table-column :label="$t('关键里程碑')">
            <template slot="header" slot-scope="{}">
              <i v-if="validate" style="color: #ff4949; margin-right: 4px">*</i>
              <span>{{ $t("关键里程碑") }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'futureMilestonesList.' + scope.$index + '.keyMilestones'"
                :rules="rules.keyMilestones"
              >
                <el-input v-model="scope.row.keyMilestones" show-word-limit :maxlength="200" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('时间点')">
            <template slot="header" slot-scope="{}">
              <i v-if="validate" style="color: #ff4949; margin-right: 4px">*</i>
              <span>{{ $t("时间点") }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'futureMilestonesList.' + scope.$index + '.timePoint'"
                :rules="rules.timePoint"
              >
                <el-date-picker
                  v-model="scope.row.timePoint"
                  clearable
                  type="datetime"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  :placeholder="$t('时间点')"
                />
              </el-form-item>
            </template>
          </el-table-column>
        </formInnerTable>
        <!--    核心管理团队    -->
        <formInnerTable
          title="核心管理团队"
          :data-list="form.coreManagementTeamList"
          :init-data="initData.coreProducts"
        >
          <el-table-column :label="$t('职位')">
            <template slot="header" slot-scope="{}">
              <i v-if="validate" style="color: #ff4949; margin-right: 4px">*</i>
              <span>{{ $t("职位") }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'coreManagementTeamList.' + scope.$index + '.position'"
                :rules="rules.position"
              >
                <el-input v-model="scope.row.position" show-word-limit :maxlength="60" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('姓名')">
            <template slot="header" slot-scope="{}">
              <i v-if="validate" style="color: #ff4949; margin-right: 4px">*</i>
              <span>{{ $t("姓名") }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'coreManagementTeamList.' + scope.$index + '.fullName'"
                :rules="rules.fullName"
              >
                <el-input v-model="scope.row.fullName" show-word-limit :maxlength="60" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('简介')">
            <template slot="header" slot-scope="{}">
              <i v-if="validate" style="color: #ff4949; margin-right: 4px">*</i>
              <span>{{ $t("简介") }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'coreManagementTeamList.' + scope.$index + '.introduction'"
                :rules="rules.introduction"
              >
                <el-input v-model="scope.row.introduction" type="textarea" show-word-limit :maxlength="500" />
              </el-form-item>
            </template>
          </el-table-column>
        </formInnerTable>
        <el-col :span="24">
          <el-form-item label="管理团队描述">
            <el-input v-model="form.descriptionOfTheManagementTeam" type="textarea" show-word-limit :maxlength="2000" />
          </el-form-item>
        </el-col>
        <!--    竞争分析（国内外）    -->
        <formInnerTable
          title="竞争分析（国内外）"
          :data-list="form.competitionAnalysisList"
          :init-data="initData.coreProducts"
        >
          <el-table-column :label="$t('竞品公司')">
            <template slot="header" slot-scope="{}">
              <i v-if="validate" style="color: #ff4949; margin-right: 4px">*</i>
              <span>{{ $t("竞品公司") }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'competitionAnalysisList.' + scope.$index + '.competingCompany'"
                :rules="rules.competingCompany"
              >
                <el-input v-model="scope.row.competingCompany" type="textarea" show-word-limit :maxlength="200" />
              </el-form-item>
            </template>
          </el-table-column>
        </formInnerTable>
        <!--    潜在风险    -->
        <formInnerTable
          title="潜在风险"
          :data-list="form.potentialRisksList"
          :init-data="initData.coreProducts"
        >
          <el-table-column :label="$t('风险')">
            <template slot="header" slot-scope="{}">
              <i v-if="validate" style="color: #ff4949; margin-right: 4px">*</i>
              <span>{{ $t("风险") }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'potentialRisksList.' + scope.$index + '.risk'"
                :rules="rules.risk"
              >
                <el-input v-model="scope.row.risk" show-word-limit :maxlength="200" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('风险分析')">
            <template slot="header" slot-scope="{}">
              <i v-if="validate" style="color: #ff4949; margin-right: 4px">*</i>
              <span>{{ $t("风险分析") }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'potentialRisksList.' + scope.$index + '.riskAnalysis'"
                :rules="rules.riskAnalysis"
              >
                <el-input v-model="scope.row.riskAnalysis" type="textarea" show-word-limit :maxlength="2000" />
              </el-form-item>
            </template>
          </el-table-column>
        </formInnerTable>
        <!--    融资历史和估值    -->
        <formInnerTable
          title="融资历史和估值"
          :data-list="form.fundingHistoryList"
          :init-data="initData.coreProducts"
        >
          <el-table-column :label="$t('融资时间')">
            <template slot-scope="scope">
              <el-date-picker
                v-model="scope.row.financingTime"
                clearable
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                :placeholder="$t('融资时间')"
              />
            </template>
          </el-table-column>
          <el-table-column :label="$t('融资金额（万）')">
            <template slot-scope="scope">
              <el-form-item>
                <Money v-model="scope.row.financingAmount" :placeholder="$t('融资金额（万）')" unit="w" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('投后估值（万）')">
            <template slot-scope="scope">
              <el-form-item>
                <Money v-model="scope.row.postMoneyValuation" :placeholder="$t('投后估值（万）')" unit="w" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('领投方')">
            <template slot-scope="scope">
              <el-form-item>
                <el-input v-model="scope.row.leadInvestor" show-word-limit :maxlength="50" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('跟投方')">
            <template slot-scope="scope">
              <el-form-item>
                <el-input v-model="scope.row.followTheBidder" show-word-limit :maxlength="50" />
              </el-form-item>
            </template>
          </el-table-column>
        </formInnerTable>
        <!--    近几年财务数据    -->
        <formInnerTable
          title="近几年财务数据"
          :data-list="form.financialDataList"
          :init-data="initData.coreProducts"
        >
          <el-table-column :label="$t('年度')">
            <template slot="header" slot-scope="{}">
              <i v-if="validate" style="color: #ff4949; margin-right: 4px">*</i>
              <span>{{ $t("年度") }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'financialDataList.' + scope.$index + '.year'"
                :rules="rules.year"
              >
                <el-input v-model="scope.row.year" show-word-limit :maxlength="20" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('收入（万）')">
            <template slot="header" slot-scope="{}">
              <i v-if="validate" style="color: #ff4949; margin-right: 4px">*</i>
              <span>{{ $t("收入（万）") }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'financialDataList.' + scope.$index + '.income'"
                :rules="rules.income"
              >
                <Money v-model="scope.row.income" :placeholder="$t('收入（万）')" unit="w" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('净利润（万）')">
            <template slot="header" slot-scope="{}">
              <i v-if="validate" style="color: #ff4949; margin-right: 4px">*</i>
              <span>{{ $t("净利润（万）") }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'financialDataList.' + scope.$index + '.netProfit'"
                :rules="rules.netProfit"
              >
                <Money v-model="scope.row.netProfit" :placeholder="$t('净利润（万）')" unit="w" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('负债（万）')">
            <template slot="header" slot-scope="{}">
              <i v-if="validate" style="color: #ff4949; margin-right: 4px">*</i>
              <span>{{ $t("负债（万）") }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'financialDataList.' + scope.$index + '.beInDebt'"
                :rules="rules.beInDebt"
              >
                <Money v-model="scope.row.beInDebt" :placeholder="$t('负债（万）')" unit="w" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('经营现金流（万）')">
            <template slot="header" slot-scope="{}">
              <i v-if="validate" style="color: #ff4949; margin-right: 4px">*</i>
              <span>{{ $t("经营现金流（万）") }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'financialDataList.' + scope.$index + '.operatingCashFlow'"
                :rules="rules.operatingCashFlow"
              >
                <Money v-model="scope.row.operatingCashFlow" :placeholder="$t('经营现金流（万）')" unit="w" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column>
            <template slot="header" slot-scope="{}">
              <i v-if="validate" style="color: #ff4949; margin-right: 4px">*</i>
              <span>{{ $t("总资产") }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'financialDataList.' + scope.$index + '.totalAssets'"
                :rules="rules.totalAssets"
              >
                <Money v-model="scope.row.totalAssets" :placeholder="$t('总资产')" unit="w" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column width="250">
            <template slot="header" slot-scope="{}">
              <i v-if="validate" style="color: #ff4949; margin-right: 4px">*</i>
              <span>{{ $t("现金余额（货币+可交易资产）") }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'financialDataList.' + scope.$index + '.cashBalance'"
                :rules="rules.cashBalance"
              >
                <Money v-model="scope.row.cashBalance" :placeholder="$t('现金余额（货币+可交易资产）')" unit="w" />
              </el-form-item>
            </template>
          </el-table-column>
        </formInnerTable>
        <!--    融资需求和估值    -->
        <el-col :span="24">
          <div class="area-header" style="margin-top: 20px;">
            <span class="area-header-title">{{ $t('融资需求和估值') }}</span>
          </div>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('融资额（万）')" prop="financingNeeds.financingAmount">
            <Money v-model="form.financingNeeds.financingAmount" :placeholder="$t('融资额（万）')" unit="w" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('投前估值（万）')" prop="preInvestmentValuation">
            <Money v-model="form.financingNeeds.preInvestmentValuation" :placeholder="$t('投前估值（万）')" unit="w" />
          </el-form-item>
        </el-col>

        <!--    退出策略    -->
        <formInnerTable
          title="退出策略"
          :data-list="form.evaluationExitStrategyList"
          :init-data="initData.coreProducts"
        >
          <el-table-column :label="$t('策略')">
            <template slot="header" slot-scope="{}">
              <i v-if="validate" style="color: #ff4949; margin-right: 4px">*</i>
              <span>{{ $t("策略") }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'evaluationExitStrategyList.' + scope.$index + '.tactics'"
                :rules="rules.tactics"
              >
                <el-input v-model="scope.row.tactics" type="textarea" show-word-limit :maxlength="2000" />
              </el-form-item>
            </template>
          </el-table-column>
        </formInnerTable>
        <!--    建议&下一步    -->
        <el-col :span="24">
          <div class="area-header" style="margin-top: 20px;">
            <span class="area-header-title">{{ $t('建议&下一步') }}</span>
          </div>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('内部')" prop="recommend.internal">
            <el-input v-model="form.recommend.internal" type="textarea" :placeholder="$t('内部')" show-word-limit :maxlength="2000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('外部')" prop="recommend.external">
            <el-input v-model="form.recommend.external" type="textarea" :placeholder="$t('外部')" show-word-limit :maxlength="2000" />
          </el-form-item>
        </el-col>

        <!--    其他    -->
        <el-col :span="24">
          <div class="area-header" style="margin-top: 20px;">
            <span class="area-header-title">{{ $t('其他') }}</span>
          </div>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('其他LP要求')" prop="companyProfile">
            <el-input v-model="form.other.otherLpRequirements" type="textarea" :placeholder="$t('其他LP要求')" show-word-limit :maxlength="2000" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('是否利益冲突')" prop="other.isThereAConflictOfInterest">
            <dict-select
              v-model="form.other.isThereAConflictOfInterest"
              dictionary="yes-no-unknown"
              :placeholder="$t('是否利益冲突')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('是否返投')" prop="other.whetherToReturn">
            <dict-select
              v-model="form.other.whetherToReturn"
              dictionary="yes-no-unknown"
              :placeholder="$t('是否返投')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('是否科技成果转化')" prop="other.achievementTransformation">
            <dict-select
              v-model="form.other.achievementTransformation"
              dictionary="yes-no-unknown"
              :placeholder="$t('是否科技成果转化')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="其他">
            <el-input v-model="form.otherContent" type="textarea" show-word-limit :maxlength="2000" />
          </el-form-item>
        </el-col>

        <!-- 附件列表 -->
        <el-col :span="24">
          <FileTable :list.sync="form.fileList" data-type="preliminaryAssessment" />
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import formInnerTable from '@/views/saas/yueyin/deal/component/formInnerTable'
import MainBodySelect from '@/components/MainBodySelect'
import { getDealName } from '@/api/base/deal/dealBase'
import {
  getSysYueyinPreliminaryProjectEvaluationInfo,
  saveSysYueyinPreliminaryProjectEvaluationInfo,
  queryCompanyDataByDealId, getCompanyBaseInfo
} from '@/api/sass/yueyin/deal/preliminaryAssessment/sysYueyinPreliminaryProjectEvaluationInfo'

export default {
  name: 'PreliminaryAssessment',
  components: {
    formInnerTable,
    MainBodySelect
  },
  data() {
    return {
      validate: false,
      // 表单参数
      form: {
        id: undefined,
        dealId: undefined,
        dealName: undefined,
        internetSite: undefined,
        established: undefined,
        legalPerson: undefined,
        registeredCapital: undefined,
        registration: undefined,
        companyProfile: undefined,
        projectSource: undefined,
        investmentLogic: undefined,
        industryNeeds: undefined,
        actId: undefined,
        actStatus: undefined,
        actTitle: undefined,
        remark: undefined,
        createBy: undefined,
        updateBy: undefined,
        createTime: undefined,
        updateTime: undefined,
        delFlag: undefined,
        coreProductsList: [],
        futureMilestonesList: [],
        coreManagementTeamList: [],
        competitionAnalysisList: [],
        potentialRisksList: [],
        fundingHistoryList: [],
        financialDataList: [],
        evaluationExitStrategyList: [],
        financingNeeds: {
          financingAmount: 0,
          preInvestmentValuation: 0
        },
        recommend: {
          internal: '',
          external: ''
        },
        other: {
          otherLpRequirements: '',
          isThereAConflictOfInterest: undefined,
          whetherToReturn: undefined,
          achievementTransformation: undefined
        },
        fileList: []
      },
      // 表单校验
      rules: {
        /* productService: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        keyMilestones: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        timePoint: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        position: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        fullName: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        introduction: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        competingCompany: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        risk: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        riskAnalysis: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        year: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        income: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        netProfit: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        beInDebt: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        operatingCashFlow: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        'financingNeeds.financingAmount': [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        'financingNeeds.preInvestmentValuation': [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        tactics: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        'recommend.internal': [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        'recommend.external': [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        'other.isThereAConflictOfInterest': [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        'other.whetherToReturn': [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        'other.achievementTransformation': [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        'financialDataList.year': [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        'financialDataList.income': [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        'financialDataList.netProfit': [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        'financialDataList.beInDebt': [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        'financialDataList.operatingCashFlow': [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        'financialDataList.totalAssets': [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ],
        'financialDataList.cashBalance': [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ]*/

      },
      // 遮罩层
      loading: false,
      // 操作按钮默认不展示
      buttonShow: true,
      initData: {
        coreProducts: {}
      }
    }
  },
  created() {
    this.$bus.$emit('async_done')
  },
  methods: {
    // 初始化数据
    async init(data) {
      console.log('参数', data)
      this.loading = true
      if (data != null && data.id !== undefined) {
        getSysYueyinPreliminaryProjectEvaluationInfo(data.id).then(response => {
          this.form = response.data
          if (this.form.financingNeeds === undefined || this.form.financingNeeds === null) {
            this.form.financingNeeds = {
              financingAmount: 0,
              preInvestmentValuation: 0
            }
          }
          if (this.form.recommend === undefined || this.form.recommend === null) {
            this.form.recommend = {
              internal: '',
              external: ''
            }
          }
          if (this.form.other === undefined || this.form.other === null) {
            this.form.other = {
              otherLpRequirements: '',
              isThereAConflictOfInterest: undefined,
              whetherToReturn: undefined,
              achievementTransformation: undefined
            }
          }
          this.loading = false
        })
      } else {
        this.reset()
        // 默认带出流程中必须要传的附件
        if (data !== null) {
          this.form.fileList = data.fileList
        }
        this.form.input5 = await getDealName(this.$route.query.id) + '-项目初步评估'
        // 设置当前默认选中项目 并且获取天眼查信息
        this.form.dealId = this.$route.query.id
        this.dealIdChange(this.form.dealId)
        this.loading = false
      }
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        dealId: undefined,
        dealName: undefined,
        internetSite: undefined,
        established: undefined,
        totalAssets: undefined,
        cashBalance: undefined,
        legalPerson: undefined,
        registeredCapital: undefined,
        registration: undefined,
        companyProfile: undefined,
        projectSource: undefined,
        investmentLogic: undefined,
        industryNeeds: undefined,
        actId: undefined,
        actStatus: undefined,
        actTitle: undefined,
        remark: undefined,
        createBy: undefined,
        updateBy: undefined,
        createTime: undefined,
        descriptionOfTheManagementTeam: undefined,
        otherContent: undefined,
        updateTime: undefined,
        delFlag: undefined,
        coreProductsList: [],
        futureMilestonesList: [],
        coreManagementTeamList: [],
        competitionAnalysisList: [],
        potentialRisksList: [],
        fundingHistoryList: [],
        financialDataList: [],
        evaluationExitStrategyList: [],
        financingNeeds: {
          financingAmount: 0,
          preInvestmentValuation: 0
        },
        recommend: {
          internal: '',
          external: ''
        },
        other: {
          otherLpRequirements: '',
          isThereAConflictOfInterest: undefined,
          whetherToReturn: undefined,
          achievementTransformation: undefined
        },
        fileList: []
      }
      this.resetForm('form')
    },
    // 取消按钮
    cancel() {
      this.$parent.$parent.formOpen = false
      this.$parent.$parent.reset()
    },
    // 关闭form页面
    closeForm(type) {
      // 关闭form页面遮罩层
      this.loading = false
      if (type !== 'actSave') {
        // 关闭form页面
        this.$parent.$parent.formOpen = false
        // 刷新list页面
        this.$parent.$parent.getList()
      }
    },
    /** 提交按钮 */
    submitForm: function(type) {
      return new Promise((resolve, reject) => {
        this.$refs['form'].validate(valid => {
          // 验证数据
          if (valid) {
            // 弹出遮罩层
            this.loading = true
            // 保存数据
            saveSysYueyinPreliminaryProjectEvaluationInfo(this.form).then(response => {
              console.log('type', type)
              console.log('保存结果', response)
              if (response.code === 200) {
                // 点击的按钮是保存并启动流程
                if (type === 'process') {
                  console.log('启动流程')
                  // 设置数据id方式启动流程后取消并再次启动会创建多条记录
                  this.form.id = response.data.id
                  // 启动流程
                  this.startProcess(response.data.id)
                  // 点击的仅保存
                } else {
                  console.log('仅保存')
                  this.msgSuccess(this.$t('保存成功'))
                  // 关闭form页面
                  this.closeForm(type)
                }
                this.form.id = response.data.id
                console.log('返回id', response.data.id)
                resolve(response.data.id)
              } else {
                this.msgError(response.msg)
                this.loading = false
                reject(response)
              }
            }).catch(() => {
              this.loading = false
            })
          } else {
            reject()
            this.locationError(document)
          }
        })
      })
    },
    // 启动流程
    startProcess: async function(dataId) {
      const dealName = await getDealName(this.$route.query.id)
      this.loading = false
      // 启动流程时候传入的参数
      const processData = {}
      // 待办标题
      processData.title = '「' + dealName + '」' + ':项目初步评估'
      // 业务表名
      processData.dataTable = 'sys_yueyin_preliminary_project_evaluation_info'
      console.log('业务id', dataId)
      // 业务ID
      processData.dataId = dataId
      // 业务表单地址(待办页面需要打开的页面)
      processData.formPath = '@/views/saas/yueyin/deal/preliminaryAssessment'
      processData.viewPath = '@/views/saas/yueyin/deal/preliminaryAssessment'
      // 菜单标识(根据菜单标识判断的走哪个流程)
      processData.menuKey = 'sys_yueyin_preliminary_project_evaluation_info'
      this.startProcessByMenu(processData, () => {
        this.form.actStatus = 'D'
        this.msgSuccess(this.$t('数据保存成功,流程启动成功'))
        this.closeForm()
      })
    },
    dealIdChange(item) {
      /*
        根据id去查他关联的公司名称和tcyId 都在company_base 表
        然后根据两个数据去查天眼查数据  返回的值 就翻译一下 一一对应就好了
        接口是：/base/fundBase/fundDetailsByName
        两个属性对应到 传参对象的属性就行了
        或者自己写个接口 在接口里面直接调天眼查的service也行
       */
      queryCompanyDataByDealId(item).then(result => {
        this.form.projectSource = result.data.dealSource
        const sendData = {
          id: result.data.id,
          tycId: result.data.tycId,
          companyName: result.data.companyName
        }
        getCompanyBaseInfo(sendData).then(res => {
          console.log('新接口返回数据', res)
          this.form.established = res.data.setDate
          this.form.legalPerson = res.data.legalPerson
          this.form.registeredCapital = res.data.capitalRegistered
          this.form.registration = res.data.detailsRegistered
        })
      })
    }
  }
}
</script>

<style scoped>

</style>
